<?php

namespace app\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Product;

/**
 * ProductSearch represents the model behind the search form about `app\models\Product`.
 */
class AuctionSearch extends Auction
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['auctionid','degree', 'actcount', 'reacount', 'can_robot', 'have_cost', 'can_give', 'state', 'created_at', 'updated_at'], 'integer'],
            [['name'], 'safe'],
            [['market_val', 'cost', 'return_rate', 'start_price', 'scope', 'fee', 'lowest_price', 'highest_price'], 'number'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Auction::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'pid' => $this->auctionid,
            'market_val' => $this->market_val,
            'cost' => $this->cost,
            'return_rate' => $this->return_rate,
            'start_price' => $this->start_price,
            'scope' => $this->scope,
            'fee' => $this->fee,
            'degree' => $this->degree,
            'lowest_price' => $this->lowest_price,
            'highest_price' => $this->highest_price,
            'actcount' => $this->actcount,
            'reacount' => $this->reacount,
            'can_robot' => $this->can_robot,
            'have_cost' => $this->have_cost,
            'can_give' => $this->can_give,
            'state' => $this->state,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ]);

        return $dataProvider;
    }
}
